﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace EntLibSample.DALCommon
{
    public class SqlExecution
    {
        public Database sqlDB { get; set; }
        public DbCommand dbCommand { get; set; }
        public DbTransaction dbTransaction { get; set; }

        public int ExecuteNonQuery()
        {
            if (dbTransaction != null)
            {
                return sqlDB.ExecuteNonQuery(dbCommand, dbTransaction);
            }
            else
            {
                return sqlDB.ExecuteNonQuery(dbCommand);
            }
        }

        public DataSet ExecuteDataSet()
        {
            if (dbTransaction != null)
            {
                return sqlDB.ExecuteDataSet(dbCommand, dbTransaction);
            }
            else
            {
                return sqlDB.ExecuteDataSet(dbCommand);
            }
        }

        public object ExecuteScalar()
        {
            if (dbTransaction != null)
            {
                return sqlDB.ExecuteScalar(dbCommand, dbTransaction);
            }
            else
            {
                return sqlDB.ExecuteScalar(dbCommand);
            }
        }

        public IDataReader ExecuteReader()
        {
            if (dbTransaction != null)
            {
                return sqlDB.ExecuteReader(dbCommand, dbTransaction);
            }
            else
            {
                return sqlDB.ExecuteReader(dbCommand);
            }
        }
    }
}
